<template>
	<view>
		<swiper :current='current' class="swiperbox" @change="changeswiper" :indicator-dots="false" :autoplay="false">
			<swiper-item v-for="(item,index) in swiperlist">
				<u-empty v-if="orderlist==''"></u-empty>
				<view class="swiper-item" v-else>
					<scroll-view scroll-y="true" class="scrollview" @scrolltolower="getlow">
						<template v-if="marks==1">
							<Delivery :current='current' :bigcurrent='bigcurrent' :orderlist='orderlist'></Delivery>
						</template>
						<template v-else>
							<student :current='current' :bigcurrent='bigcurrent' :orderlist='orderlist' >
								
							</student>
						</template>
					</scroll-view>
				</view>
			</swiper-item>
		</swiper>

	</view>
</template>

<script>
	import Delivery from './Delivery.vue';
	import student from './student.vue';
	export default {
		components: {
			Delivery,
			student
		},
		props: {
			swiperlist: {
				type: Array,
				default: []
			},
			current: {
				type: Number,
				default: 0
			},

			marks: {
				type: Number,
				default: 0
			},
			searchtext: {
				type: String,
				default: ''
			},
			bigcurrent:{
				type: Number,
				default: 1
			}
		},
		name: "swiperitem",
		data() {
			return {
				yztitle: '',
				orderlist: [],
				seachphonetext: '',
				page:1,
				threearea:''
			};
		},
		beforeDestroy() {
			uni.$off('changelou')
			uni.$off('fatherbigtabchange')
			uni.$off('studentbigtab')
			uni.$off('jiedanle')
			uni.$off('seachphone')
		},
		watch:{
			current:{
				handler(nval,oval){
					console.log(nval);
					this.page=1
					this.orderlist=[]
					
				}
			}
		},
		mounted() {
			
			this.init()
			uni.$on('changelou', (e) => {
				if(e=='郑大松园餐厅西侧菜鸟驿站'||e=='郑州大学柳园菜鸟驿站'||e=='郑大本源体育场北侧'){
					this.threearea = e
				}else{
					this.yztitle = e
					this.threearea = ''
				}
				this.page=1
				this.orderlist=[]
				this.init()
			})
			uni.$on('studentbigtab', (e) => {
				this.page=1
				this.orderlist=[]
				this.bigcurrent = e
				this.init()
			})
			
			uni.$on('jiedanle', (e) => {
				this.page=1
				this.orderlist=[]
				this.init()
			})
			
			uni.$on('upgg', (e) => {
				this.page=1
				this.orderlist=[]
				this.init()
			})
			
			uni.$on('arrived', (e) => {
				this.page=1
				this.orderlist=[]
				this.init()
			})
			
			uni.$on('starps', (e) => {
				this.page=1
				this.orderlist=[]
				this.init()
			})
			uni.$on('seachphone', (e) => {
				this.page=1
				this.orderlist=[]
				this.seachphonetext = e
				this.init()
				this.seachphonetext = ''
			})
			uni.$on('fatherbigtabchange', (e) => {
				if (e === 0) {
					this.bigcurrent = 0
				} else {
					this.bigcurrent = 1
				}
				this.page=1
				this.orderlist=[]
				this.init()
			})
			// uni.$on('fathersmalltabchange', (e) => {
			// 	this.page=1
			// 	this.orderlist=[]
			// 	console.log(this.orderlist);
			// 	this.init()
			// })
			
		},
		methods: {
			getlow() {
				console.log('触底了');
				this.page ++
				this.init()
			},
			init() {
				if (this.marks == 1) {
					this.$api.post('/Delivery/Deliveryrecolst', {
						keyword: this.seachphonetext,
						type: this.current,
						op: this.bigcurrent+1,
						address: this.yztitle=='全部'?'':this.yztitle,
						yztitle:this.threearea,
						page:this.page
					}).then(res => {
						if(res.data==''){
							this.$toast('没有更多数据了~')
						}
						this.orderlist = [...this.orderlist,...res.data]
						this.orderlist.map(item => {
							if (item.images != null) {
								return item.images = item.images.split(",");
							}
						})
					})
				} else {
					this.$api.post('/Delivery/orderlst', {
						type: this.current+1, //1=代取件,2=已取件, 3 =已送达,4=取件失败
						op: this.bigcurrent+1 ,//1=取包裹 2=寄包裹
						page:this.page
					}).then(res => {
						if(res.data==''){
							this.$toast('没有更多数据了~')
						}
						this.orderlist = [...this.orderlist,...res.data]
						this.orderlist.map(item => {
							if (item.images != null) {
								return item.images = item.images.split(",");
							}
						})
						
					}).catch(res=>{
						
					})
				}


			},
			changeswiper(e) {
				// this.current = e.detail.current
				this.page = 1
				this.orderlist=[]
				if (this.marks == 1) {
					this.$api.post('/Delivery/Deliveryrecolst', {
						keyword: this.seachphonetext,
						type: e.detail.current,
						op: this.bigcurrent+1,
						address: this.yztitle=='全部'?'':this.yztitle,
						yztitle:this.threearea,
						page:this.page
					}).then(res => {
						this.orderlist = [...this.orderlist,...res.data]
						this.orderlist.map(item => {
							if (item.images != null) {
								return item.images = item.images.split(",");
							}
						})
					})
				} else {
					this.$api.post('/Delivery/orderlst', {
						type: e.detail.current+1, //2=已取件, 3 =已送达,4=取件失败
						op: this.bigcurrent+1 ,//1=取包裹 2=寄包裹
						page:this.page
					}).then(res => {
						console.log(res);
						this.orderlist = [...this.orderlist,...res.data]
						this.orderlist.map(item => {
							if (item.images != null) {
								return item.images = item.images.split(",");
							}
						})
						
					}).catch(res=>{
						console.log(res);
					})
				}
				this.$emit('changeswiper', e.detail.current)
			},
		}
	}
</script>

<style lang="scss">
	.swiperbox {
		width: 100%;
		height: calc(100vh - 158px);

		.scrollview {
			height: calc(100vh - 178px);
		}
	}
</style>